<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运动康复方案</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.4.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../js/login_common.js" charset="utf-8"></script>
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <style>
    </style>
    <script>
        $.ajaxSetup({
            async : false
        });
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //常规用法
            laydate.render({
                elem: '#stime'
                ,type: 'year'
            });
            //常规用法
            laydate.render({
                elem: '#etime'
                ,type: 'year'
            });
        });
        $(function(){
            if(loginObj.user.company!='教练员'){
                $("#add").hide();
            }
            /*    $("#add").click(function(){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '心理训练方案增加页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: 'AtsSchemeAddOrupdate.html', //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                })*/
            /*    $("#seachTable").on("click",function(){
                    //执行重载
                    //带条件查询
                    table2.reload({
                        url: '../../../mentalTrainingController/selectAll',
                        where: {
                            schemeName: $("#schemeName").val(),
                            stime: $("#stime").val(),
                            etime: $("#etime").val(),
                            month: $("#month").val()
                        },
                        page: { curr: 1 }
                    });
                })*/
        });
    </script>
</head>
<body style="padding: 5px;">

<script type="text/html" id="toolbarDemo">
    {{#
    if(loginObj.user.company=='教练员'){ }}
    <div class="layui-inline">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除</button>
    </div>
    {{# } }}
    搜索：
    <div class="layui-inline">
        <input class="layui-input" name="schemeName" id="schemeName" placeholder="方案名称关键字搜索" autocomplete="off">
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="stime" name="stime" placeholder="请选择开始日期" >
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="etime" name="etime"  placeholder="请选择结束日期" >
    </div>
    <div class="layui-input-inline">
        <input type="number" class="layui-input" id="month" name="month" placeholder="请输入方案月份">
    </div>
    <input type="button" id="seachTable" class="layui-btn layui-btn-normal" lay-event="seachTable" value="搜索" />
    {{#
    if(loginObj.user.company=='教练员'){ }}
    <button type="button" class="layui-btn layui-btn-normal" lay-event="add" id="add">新增运动康复方案</button>
    {{# } }}
    </script>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script>

    var table2=null;
    layui.use('table', function(){
        var table = layui.table;
        table2= table.render({
            elem: '#test'
            ,url:'../../../RecoveryAtsSchemeController/selectAllRe'
            ,toolbar: '#toolbarDemo'
            ,title: '运动康复方案'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{toolbar:'#Allone', title:'方案名称', width:120}
                ,{field:'year', title:'方案年度', width:80}
                ,{field:'month', title:'方案月份', width:60, sort: true}
                ,{toolbar: '#type', title:'方案类型', width:120}
                ,{title:'附件1', width:70,toolbar: '#fileone'}
                ,{title:'附件2', width:70,toolbar: '#filetwo'}
                ,{title:'附件3', width:70,toolbar: '#filethree'}
                ,{field:'coachName', title:'教练员姓名', width:120}
                ,{field:'resultTime', title:'反馈时间', width:120}
                ,{field:'resultExp', title:'实施情况', width:120}
                ,{field:'resultEffect', title:'实施效果', width:120}
                ,{field:'resultFile',toolbar: '#filefour',title:'实施附件', width:120}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:320}
            ]]
            ,page: true//开启分页
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'edit'){
                var data1 = obj.data;//获取当前行
                //iframe层
                layer.open({
                    type: 2,
                    title: '方案新增页面',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['40%', '60%'],
                    content: 'RecoveryAtsSchemeAdd.html?id='+data1.schemeId, //iframe的url
                    end:function(){

                    }
                });
            }else if (obj.event === 'details') {
                var url3 = "../../../RecoveryAtsSchemeController/addExp";
                var data3 = {schemeId: data.schemeId, isRead: 1, readTime: getFormatDate()};
                $.post(url3, data3, function (obj3) {
                    if (obj3.num === 1) {
                        console.info("已阅读" + obj3.msg);
                    }
                });
                //iframe层
                layer.open({
                    type: 2,
                    title: '查看详情',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area:['80%', '90%'],//大小
                    content: 'RecoveryAtsSchemeDetails.html?id='+ data.schemeId, //iframew的url
                    end: function () {
                        table2.reload();//刷新父页面;
                    }
                });
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行吗', function (index) {
                    var url = "../../../RecoveryAtsSchemeController/updateIsva";
                    var datas = {schemeId: obj.data.schemeId}
                    $.post(url, datas, function (obj) {
                        if(obj.num==1){
                            layer.msg(obj.msg, {
                                icon: 6,
                                time: 500
                            }, function () {
                                window.location.reload();
                            });
                        }else{
                            layer.msg(obj.msg, {
                                icon: 2,
                                time: 500
                            }, function () {
                                return;
                            });
                        }
                    }, "json")
                });

            }else if (obj.event === 'shishi') {
                var data1 = obj.data;//获取当前行
                var url="../../../RecoveryAtsSchemeController/selectAudit";
                var datatwo={schemeId:data1.schemeId};
                $.post(url,datatwo,function(obj){
                    console.info(obj);
                    if(obj.auditState=="0"){
                        layer.msg("请您先申请咨询,通过后在进行此操作!",{
                            icon:7,
                            time:3000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="40"){
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '反馈信息页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['80%', '80%'],
                            content: 'RecoveryAtsSchemeResults.html?id='+data1.schemeId+"&resultExp="+data1.resultExp, //iframe的url
                            end:function(){

                            }
                        });
                    }else if(obj.auditState=="30"){
                        layer.msg("专家已获知待回复，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="21"){
                        layer.msg("中心领导未通过，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="20"){
                        layer.msg("中心领导申请通过了，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="10"){
                        layer.msg("正在申请中，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }
                },"json");
            }else if(obj.event === 'detail'){
                var data1 = obj.data;//获取当前行
                var url="../../../RecoveryAtsSchemeController/selectAudit";
                var datatwo={schemeId:data1.schemeId};
                var urlll="../../../RecoveryAtsSchemeController/selectAuditcount";
                var datathree={schemeId:data1.schemeId};
                $.post(urlll,datathree,function(objss){

                    if(objss.num==0){
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '申请审核咨询页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['80%', '80%'],
                            content: 'RecoveryAtsSchemeAudit.html?id='+data1.schemeId, //iframe的url
                            end:function(){
                                table2.reload();
                            }
                        });
                    }
                },"json");
                $.post(url,datatwo,function(obj){
                    if(obj.auditState=="10"){
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '申请审核咨询页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['80%', '80%'],
                            content: 'RecoveryAtsSchemeAudit.html?id='+data1.schemeId, //iframe的url
                            end:function(){
                                table2.reload();
                            }
                        });
                    }else if(obj.auditState=="20"){
                        layer.msg("中心领导申请通过了，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="21"){
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '申请审核咨询页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['80%', '80%'],
                            content: 'RecoveryAtsSchemeAudit.html?id='+data1.schemeId+"&type=21", //iframe的url
                            end:function(){
                                table2.reload();
                            }
                        });
                    }else if(obj.auditState=="30"){
                        layer.msg("专家已获知待回复，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }else if(obj.auditState=="40"){
                        layer.msg("专家已回复，不能在进行申请操作",{
                            icon:6,
                            time:2000 //1秒关闭(如果不配置默认三秒)
                        });
                    }

                },"json");

            }

        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    layer.confirm('真的删除这些行吗', function(index){
                        var data = checkStatus.data;
                        //layer.alert(JSON.stringify(data));
                        var ids="";//需要删除的id
                        $.each(data,function(index,idem){
                            ids+=idem.schemeId+",";
                        })
                        if(ids==""){
                            layer.msg("请您选中需要删除的内容,不能为空!");
                        }
                        var url="../../../RecoveryAtsSchemeController/deleteAllone";
                        var datas={schemeId:ids};
                        $.post(url,datas,function(obj){
                            layer.msg(obj.msg, {
                                icon: 6,
                                time: 1000
                            }, function () {
                                window.location.reload();
                            });
                        },"json");
                    });
                    break;
                case 'seachTable':
                    var schemeName=$("#schemeName").val();
                    var stime=$("#stime").val();
                    var etime=$("#etime").val();
                    var month=$("#month").val();
                    if(stime.length>4){
                        layer.msg("请输入正确的年份", {
                            icon: 2,
                            time: 500
                        }, function () {
                            return;
                        });
                    }else if(etime.length>4) {
                        layer.msg("请输入正确的年份", {
                            icon: 2,
                            time: 500
                        }, function () {
                            return;
                        });
                    } else if(month&&(month<1||month>12)){
                        layer.msg("请输入正确的月份", {
                            icon: 2,
                            time: 500
                        }, function () {
                            return;
                        });
                    }else{
                        table2.reload({
                            where: {
                                schemeName: $("#schemeName").val(),
                                stime: $("#stime").val(),
                                etime: $("#etime").val(),
                                month: $("#month").val()
                            },
                            page: {
                                curr: 1
                            }
                        });
                    }
                    //显示搜索的关键字
                    $("#schemeName").val(schemeName);
                    $("#stime").val(stime);
                    $("#etime").val(etime);
                    $("#month").val(month);
                    break;

                case 'add':
                    layer.open({
                        type: 2,
                        title: '运动康复方案增加页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: 'RecoveryAtsSchemeAdd.html', //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                    break;
            };
        });
        //js获取当前时间
        function getFormatDate() {
            var nowDate = new Date();
            var year = nowDate.getFullYear();
            var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
            var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
            var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
            var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
            var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }

    });
</script>
<script type="text/html" id="barDemo">
    {{#
    if(loginObj.user.company=='教练员'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑 </a>
    <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="detail">申请咨询</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="del">删除</a>
    <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="shishi" >反馈实施</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="details" id="look">查看</a>
</script>
<script type="text/html" id="fileone">
    {{#
    if(d.file1 != null && d.file1 != ""){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.file1 }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="filetwo">
    {{#
    if(d.file2 != null && d.file2 != ""){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.file2 }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="filethree">
    {{#
    if(d.file3 != null && d.file3 != ""){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.file3 }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="filefour">
    {{#
    if(d.resultFile != null && d.resultFile != ""){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.resultFile }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="Allone">
    <div>{{d.schemeName}}</div>
</script>
<script type="text/html" id="type">
    {{#
    if(d.schemeType == "1" ){ }}
    <h5>康复方案</h5>
    {{# } }}
</script>
<script type="text/html" id="cc">
    <input type="checkbox" value="{{d.userId}}"   name="open" id="checked" lay-skin="switch" lay-filter="switchTest" lay-text="是|否" {{d.userState=="1"?"checked":""}}>
</script>
</body>
</html>
